<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Changed Settings</title>

<link rel="stylesheet" href="css/jq.css" type="text/css"
	media="print, projection, screen" />
<link rel="stylesheet" href="css/themes/blue/style.css" type="text/css"
	media="print, projection, screen"/>

<script type="text/javascript" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="js/addons/pager/jquery.tablesorter.pager.js"></script>

<script type="text/javascript" id="js">
    $(document).ready(function() {
	$("#Results").tablesorter({
	    widgets: ['zebra']
	}).tablesorterPager({
	    container:$("#pager"),
	    size:25,
	    positionFixed: false,
	});
	$("#FullTable").tablesorter({
	    widgets: ['zebra']
	});
    });
</script>
</head>

<body>

<?php

function
saveCaps()
{
    global $_GET;
    $count = $_GET['count'];
    $ga = $_GET['ga'];
    $gr = $_GET['gr'];

    $fp = fopen("run/chair-data.txt", "w");
    fprintf($fp, "# reviewer capacity, submission readers\n");
    fprintf($fp, "%s %s\n", $ga, $gr);
    fclose($fp);

    $fp = fopen("run/chair-reviewer-caps.txt", "w");
    fprintf($fp, "# reviewer, cap\n");
    for ($i = 0; $i < $count; $i++)
    {
	$map = sprintf("m%d", $i);
	$id = $_GET[$map];
	$map = sprintf("c%s", $id);
	$cap = $_GET[$map];
	if ($cap != "")
	    fprintf($fp, "%s %s\n", $id, $cap);
    }
    fclose($fp);
    printf("<b>Saved changes to reviewer caps</b>");
}

function
saveTopics($label, $prefix, $strength)
{
    global $_GET;
    $count = $_GET['count'];

    $fp = fopen(sprintf("run/chair-%s-topics.txt", $label), "w");
    fprintf($fp, "# %s, topic, strength (1=expert)\n", $label);
    for ($i = 0; $i < $count; $i++)
    {
	$map = sprintf("%s%d", $prefix, $i);
	$rid = $_GET[$map];
	$map = sprintf("t%d", $i);
	$tid = $_GET[$map];
	if ($rid && $tid)
	    fprintf($fp, "%s %s %d\n", $rid, $tid, $strength);
    }
    fclose($fp);
    printf("<b>Saved changes to %s topics</b>", $label);
}

function
saveConflicts($label)
{
    global $_GET;
    $count = $_GET['count'];

    $fp = fopen(sprintf("run/chair-%s.txt", $label), "w");
    fprintf($fp, "# sub_id, rev_id\n");
    for ($i = 0; $i < $count; $i++)
    {
	$map = sprintf("s%d", $i);
	$sub_id = $_GET[$map];
	$map = sprintf("r%d", $i);
	$rev_id = $_GET[$map];
	if ($sub_id && $rev_id)
	    fprintf($fp, "%s %s\n", $sub_id, $rev_id);
    }
    fclose($fp);
    printf("<b>Saved changes to chair-%s</b>", $label);
}


printf('<h3 align="center">Saved Changes</h3>');
require_once("header.php");


printf('<div align="center">');
printf('<input type="button" value="Rerun Sort" onclick="location=\'index.php?q=run\'"/>');
printf('</div>');
printf("\n");

$task = $_GET['task'];

if ($task == "caps")
{
    saveCaps();
}
else if ($task == "rtop")
{
    saveTopics('reviewer', 'r', 1);
}
else if ($task == "stop")
{
    saveTopics('submission', 's', 2);
}
else if ($task == "conflict" || $task == "request")
{
    saveConflicts($task);
}
else
{
    printf("<b>Unknown edit task</b>");
}

?>
</body>
</html>
